<!-- #INCLUDE Virtual="/lib.asp" -->
<!-- #INCLUDE Virtual="/lib_gen.asp" -->
<!-- #INCLUDE Virtual="/lib_json.asp" -->

<%
dim html, objXMLDom, objXMLdata
dim htmlVersion, htmlCb, pageTitle

html = getExternalHTML("http://www.politie.nl/_version")
'html = replace(html, "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">", "")

'on error resume next

'{
'  "versions": {
'    "r" : "4.45.00",
'    "e" : "6.05.00",
'    "b" : "1.1.10",
'    "m" : "unable",
'    "c" : "-cb194121"
'  }
'}

set oJson = new Json 
oJson.loadJson(html) 

application("versions.r") = oJson.getElement("versions.r")
version = application("versions.r")
pageTitle = "Status politie.nl v" & version

call checkVersion(html)

ok = (version <> "")

call generatePage(request("preview"), request.querystring("nextpage"), pageTitle, rssImage, htmlBody)

sub checkVersion(current)
	dim fname, fso, versionFile, line, newline
	
	newjson = trim(replace(current, vbcrlf, ""))
	newjson = replace(newjson, vblf, "")
	newjson = replace(newjson, vbcr, "")
	while instr(newjson, "  ") > 0
		newjson = replace(newjson, "  ", " ")
	wend
	
	set fso = Server.CreateObject("Scripting.FileSystemObject")
	versionFile = server.mappath("..\..\log\versions.log")
	
	if not fso.FileExists(versionFile) then
		set fname=fso.CreateTextFile(versionFile, true)
		fname.writeLine now() & ";" & newjson
	end if
	
	'read the last line
	set f=fso.OpenTextFile(versionFile, ForReading)
	do while f.AtEndOfStream = false
		line = f.readLine
	loop
	f.Close
	
	if len(line) then
		tmpArray = split(line, ";")
		application("versions.date") = tmpArray(0)
		oldjson = tmpArray(1)
		if oldjson <> newjson then 'a new site version is found!
			set fname=fso.OpenTextFile(versionFile, ForAppending, true)
			fname.writeLine now() & ";" & newjson
			for each sendTo in Array("sid.dane@capgemini.com", "erwin.tobben@vtspn.nl", "bruno.drenthe@vtspn.nl", "gijsbert.van.bentum@vtspn.nl")
				call sendCDOEmail("siddy@xs4all.nl", sendTo, "[POLITIEMON] New version " & application("versions.r"), "I found new version information in http://www.politie.nl/_version: " & vbcrlf & vbcrlf & newjson)
			next
		end if
	end if
	
	set fso = nothing
end sub

function htmlBody
	dim black, green, red
	black = "<tr><td style=""background-color: black;"">&nbsp;</td></tr>"
	green = "<tr><td style=""background-color: green;"">Ok</td></tr>"
	red = "<tr><td style=""background-color: red;"">Fout</td></tr>"
	divider = "<tr><td class=""traffic-light-space"">&nbsp;</td></tr>"
	
	if ok then 
		htmlBody = black & divider & black & divider & green
	else
		htmlBody = red & divider & black & divider & black
	end if
	htmlBody = "<table class=""traffic-light"">" & htmlBody & "</table>"
end function

%>
